package com.itheima.web.controller;

import com.itheima.util.OssUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Controller
@RequestMapping("/file")
public class FileController {

    //文件上传
    @PostMapping("/upload")
    @ResponseBody
    public String uploadFile(MultipartFile uploadFile) throws IOException {
        //调用阿里云工具类实现文件上传
        String url = OssUtil.upload(uploadFile.getOriginalFilename(), uploadFile.getInputStream());
        return url;
    }
}
